{% extends 'base.html' %}
{% from 'bootstrap/pagination.html' import render_pagination %}
{% block title %}管理文章{% endblock %}
{% block content %}
        <br>

    <div class="page-header">
        <h1>文章
            <small class="text-muted">{{ pagination.total }}</small>
            <span class="float-right"><a href="{{ url_for('.new_post') }}" class="btn btn-primary">发布新文章</a></span>
        </h1>
    </div>
    {% if posts %}
        <table class="table table-striped">
            <thead>
                <tr>
                    <th>编号</th>
                    <th>标题</th>
                    <th>分类</th>
                    <th>日期</th>
                    <th>评论</th>
                    <th>字数</th>
                    <th>动作</th>
                </tr>
            </thead>
        {% for post in posts %}
        <tr>
            <td>{{ loop.index+((pagination.page - 1)*20) }}</td>
            <td><a href="{{ url_for('blog.show_post',slug=post.title) }}">{{ post.title }}</a></td>
            <td><a href="{{ url_for('blog.show_category',category_id=post.category.id) }}">{{ post.category.name }}</a></td>
            <td>{{ moment(post.timestamp).format('LL') }}</td>
            <td><a href="{{ url_for('blog.show_post',slug=post.title) }}#comments">{{ post.comments|length }}</a></td>
            <td>{{ post.body|length }}</td>
            <td><a href="{{ url_for('.edit_post',post_id=post.id) }}" class="btn btn-info btn-sm">编辑</a>
                <form action="{{ url_for('.delete_post',post_id=post.id) }}" method="post" class="inline">
                    <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
                    <button type="submit" class="btn btn-danger btn-sm" onclick="return confirm('Are you sure?');">删除</button>
                </form>
            </td>
        </tr>
        {% endfor %}
        </table>
        <div class="page-footer">{{ render_pagination(pagination) }}</div>
        {% else %}
        <div class="tip"><h5>没有文章。</h5></div>
    {% endif %}

{% endblock %}